// index.js
Page({
  data: {
    showUploadTip:false,
    pageLoading: false,
    bannerList:[],
    worksListLoadStatus: 0,
    tabList: [],
    workList: [],
    pageLoading: false,
    current: 1,
    autoplay: true,
    duration: '500',
    interval: 5000,
    navigation: { type: 'dots-bar' },
    swiperImageProps: { mode: 'scaleToFill' },
    stickyProps: { zIndex: 0, offsetTop:80 },
  },
  
  properties: {
    navbarHeight: {
      type: Number,
      value: 0,
    },
  },

  privateData: {
    tabIndex: 0,
  },

  worksListPagination: {
    index: 0,
    num: 20,
  },

  onShow() {
    // this.getTabBar().init();
  },

  onLoad() {
    this.init();
  },

  onReachBottom() {
    if (this.data.goodsListLoadStatus === 0) {
      this.loadGoodsList();
    }
  },

  onPullDownRefresh() {
    this.init();
  },

  init() {
    this.loadHomePage();
  },

  loadHomePage() {
    wx.stopPullDownRefresh();

    this.setData({
      pageLoading: false,
      workList: [
        {
          "type": 1,
          "title": "王羲之行书兰亭序",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/2017/04/21/s58f9b14df3f14.jpg",
          "id":"7"
        },
        {
          "type": 1,
          "title": "黄庭坚草书杜甫寄贺兰铦诗页",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/dc/19319[1024].jpg",
          "id":"4"
        },
        {
          "type": 1,
          "title": "米芾诗牍册·行书淡墨秋山诗帖页",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/dc/51162[1024].jpg",
          "id":"5"
        },
        {
          "type": 1,
          "title": "欧阳询行书张翰帖",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/dc/777[1024].jpg",
          "id":"6"
        },
        {
          "type": 1,
          "title": "褚遂良楷书《 倪宽赞 》一",
          "time": "2025-08-08",
          "picture":"https://www.shufa.org.cn/static/upload/image/20220505/1651717466646255.jpg",
          "id":"1"
        },
        {
          "type": 1,
          "title": "褚遂良楷书《 倪宽赞 》二",
          "time": "2025-08-08",
          "picture":"https://www.shufa.org.cn/static/upload/image/20220505/1651717467369389.jpg",
          "id":"2"
        },
        {
          "type": 1,
          "title": "褚遂良楷书《 倪宽赞 》三",
          "time": "2025-08-08",
          "picture": "https://www.shufa.org.cn/static/upload/image/20220505/1651717467466757.jpg",
          "id":"3"
        }
      ],
      workList1: [
        {
          "type": 2,
          "title": "阎立本步辇图卷",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/2017/04/14/s58f0366d0cd9b.jpg",
          "id":"7"
        },
        {
          "type": 2,
          "title": "顾恺之女史箴图卷（宋摹）",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/2017/04/11/s58ec852aaaeb0.jpg",
          "id":"4"
        },
        {
          "type": 2,
          "title": "董源潇湘图卷",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/2018/10/30/s5bd7fb88a8056.jpg",
          "id":"5"
        },
        {
          "type": 2,
          "title": "欧阳询行书张翰帖",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/dc/777[1024].jpg",
          "id":"6"
        },
        {
          "type": 2,
          "title": "赵佶祥龙石图卷",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/2017/04/11/s58ec8bcd24ce1.jpg",
          "id":"1"
        },
        {
          "type": 2,
          "title": "赵昌写生蛱蝶图卷",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/2017/04/01/s58defdbf1dcc1.jpg",
          "id":"2"
        }
      ],
      tabList: [
        {
          "key":"1",
          "text":"书法"
        },
        {
          "key":"2",
          "text":"绘画"
        },{
          "key":"3",
          "text":"篆刻"
        }
      ],
      bannerList:[
        "https://img.dpm.org.cn/Uploads/Picture/2017/04/21/s58f9b14df3f14.jpg",
        "https://img.dpm.org.cn/Uploads/Picture/2017/04/14/s58f0366d0cd9b.jpg"
      ],
    });
    // fetchHome().then(({ swiper, tabList }) => {
    //   this.setData({
    //     tabList,
    //     imgSrcs: swiper,
    //     pageLoading: false,
    //   });
    //   this.loadGoodsList(true);
    // });
  },

  tabChangeHandle(e) {
    console.log(this.privateData.tabIndex)
    this.privateData.tabIndex = e.detail.value;
    this.loadWorksList(true);
  },

  async loadWorksList(fresh = false) {
    if (fresh) {
      wx.pageScrollTo({
        scrollTop: 0,
      });
    }

    this.setData({ worksListLoadStatus: 1 });

    const pageSize = this.worksListPagination.num;
    let pageIndex = this.privateData.tabIndex * pageSize + this.worksListPagination.index + 1;
    if (fresh) {
      pageIndex = 0;
    }

    if(this.privateData.tabIndex == 1) {
      this.setData({ workList: [
        {
          "type": 1,
          "title": "王羲之行书兰亭序",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/2017/04/21/s58f9b14df3f14.jpg",
          "id":"7"
        },
        {
          "type": 1,
          "title": "黄庭坚草书杜甫寄贺兰铦诗页",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/dc/19319[1024].jpg",
          "id":"4"
        },
        {
          "type": 1,
          "title": "米芾诗牍册·行书淡墨秋山诗帖页",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/dc/51162[1024].jpg",
          "id":"5"
        },
        {
          "type": 1,
          "title": "欧阳询行书张翰帖",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/dc/777[1024].jpg",
          "id":"6"
        },
        {
          "type": 1,
          "title": "褚遂良楷书《 倪宽赞 》一",
          "time": "2025-08-08",
          "picture":"https://www.shufa.org.cn/static/upload/image/20220505/1651717466646255.jpg",
          "id":"1"
        },
        {
          "type": 1,
          "title": "褚遂良楷书《 倪宽赞 》二",
          "time": "2025-08-08",
          "picture":"https://www.shufa.org.cn/static/upload/image/20220505/1651717467369389.jpg",
          "id":"2"
        },
        {
          "type": 1,
          "title": "褚遂良楷书《 倪宽赞 》三",
          "time": "2025-08-08",
          "picture": "https://www.shufa.org.cn/static/upload/image/20220505/1651717467466757.jpg",
          "id":"3"
        }
      ] });
    }else if(this.privateData.tabIndex == 2){
      this.setData({workList: [
        {
          "type": 2,
          "title": "阎立本步辇图卷",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/2017/04/14/s58f0366d0cd9b.jpg",
          "id":"7"
        },
        {
          "type": 2,
          "title": "顾恺之女史箴图卷（宋摹）",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/2017/04/11/s58ec852aaaeb0.jpg",
          "id":"4"
        },
        {
          "type": 2,
          "title": "董源潇湘图卷",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/2018/10/30/s5bd7fb88a8056.jpg",
          "id":"5"
        },
        {
          "type": 2,
          "title": "欧阳询行书张翰帖",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/dc/777[1024].jpg",
          "id":"6"
        },
        {
          "type": 2,
          "title": "赵佶祥龙石图卷",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/2017/04/11/s58ec8bcd24ce1.jpg",
          "id":"1"
        },
        {
          "type": 2,
          "title": "赵昌写生蛱蝶图卷",
          "time": "2025-08-08",
          "picture":"https://img.dpm.org.cn/Uploads/Picture/2017/04/01/s58defdbf1dcc1.jpg",
          "id":"2"
        }
      ]});
    }

    // try {
    //   const nextList = await fetchGoodsList(pageIndex, pageSize);
    //   this.setData({
    //     goodsList: fresh ? nextList : this.data.goodsList.concat(nextList),
    //     worksListLoadStatus: 0,
    //   });

    //   this.worksListPagination.index = pageIndex;
    //   this.worksListPagination.num = pageSize;
    // } catch (err) {
    //   this.setData({ worksListLoadStatus: 3 });
    // }
  },
  
  navToSearchPage() {
		console.log(1111)
    wx.navigateTo({ url: '/pages/work/search/index' });
  },

  navToActivityDetail({ detail }) {
    const { index: promotionID = 0 } = detail || {};
    wx.navigateTo({
      url: `/pages/promotion/promotion-detail/index?promotion_id=${promotionID}`,
    });
  },


})
